from product.models import Product
from django.http import HttpResponse
from django.shortcuts import render
from django.shortcuts import get_object_or_404
# 自定义查询函数    
def productselectView(request):
    # 定义查询函数,用到模型类.objects.get()方法
    # 先查询再修改再保存
    # try:
    #     product = Product.objects.get(pk="小米2000")
    #     print(product)
    # except Product.DoesNotExist:
    #     return HttpResponse('数据不存在，请重新查询')
    # product = get_object_or_404(Product,pk=24)
    # return HttpResponse(f'查询成功,名字为{product}')
    Product_cover = Product.objects.filter(product_cover__exact='')
    print(Product_cover)
    return HttpResponse(f'查询成功,名字为{Product_cover}')

def queryallView(request):
    # 定义查询函数,用到模型类.objects.get()方法
    # 先查询再修改再保存
    product = Product.objects.all()
    count_ = Product.objects.count()
    # print(count_)
    return HttpResponse(f'查询成功,名字为{product}')

    
